package com.cryptoneedle.center.source.repository.metadata;


import com.bubbles.engine.data.core.repository.BaseRepository;
import com.cryptoneedle.center.source.entity.metadata.Table;
import com.cryptoneedle.center.source.key.metadata.TableKey;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>description: 源数据源-表 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-20
 */
@Repository
public interface TableRepository extends BaseRepository<Table, TableKey> {

    @Query("  FROM Table " +
            "ORDER BY catalogName, databaseName, enabled DESC, tableName")
    List<Table> tables();

    @Query("  FROM Table " +
            "WHERE catalogName = :catalogName " +
            "ORDER BY catalogName, databaseName, enabled DESC, tableName")
    List<Table> tables(String catalogName);

    @Query("  FROM Table " +
            "WHERE catalogName = :catalogName " +
            "  AND databaseName =:databaseName " +
            "ORDER BY catalogName, databaseName, enabled DESC, tableName")
    List<Table> tables(String catalogName, String databaseName);

    @Query("  FROM Table " +
            "WHERE enabled = TRUE " +
            "ORDER BY catalogName, databaseName, enabled DESC, tableName")
    List<Table> tablesEnabled();

    @Query("  FROM Table " +
            "WHERE enabled = TRUE " +
            "  AND catalogName = :catalogName " +
            "ORDER BY catalogName, databaseName, enabled DESC, tableName")
    List<Table> tablesEnabled(String catalogName);

    @Query("  FROM Table " +
            "WHERE enabled = TRUE " +
            "  AND catalogName = :catalogName " +
            "  AND databaseName =:databaseName " +
            "ORDER BY catalogName, databaseName, enabled DESC, tableName")
    List<Table> tablesEnabled(String catalogName, String databaseName);

}